package com.sgb.kjwl.view.ui.activity.enterprise;

import android.graphics.Color;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityServiceQuoteListBinding;
import com.sgb.kjwl.di.enterprise.DaggerEnterpriseComponent;
import com.sgb.kjwl.di.enterprise.EnterpriseModule;
import com.sgb.kjwl.model.entity.enterprise.ServiceQuoteEntity;
import com.sgb.kjwl.view.ui.adapter.enterprise.ServiceQuoteAdapter;
import com.sgb.kjwl.viewmodel.enterprise.ServiceQuoteModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

public class ServiceQuoteListActivity extends AppActivity {

    @Inject
    ServiceQuoteModel model;
    private ActivityServiceQuoteListBinding binding;

    ServiceQuoteAdapter serviceQuoteAdapter;
    String teamNo = "";
    boolean isUserCenter = false;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerEnterpriseComponent.builder().appComponent(appComponent)
                .enterpriseModule(new EnterpriseModule(this))
                .build()
                .inject(this);
    }

    //设置状态栏为暗
    @Override
    protected boolean statusBarDark() {
        if (!isUserCenter)
            isUserCenter = getIntent().getBooleanExtra("isUserCenter", false);
        return isUserCenter;
    }

    @Override
    protected void initView() {
        super.initView();
        binding = DataBindingUtil.setContentView(this, R.layout.activity_service_quote_list);
        teamNo = getIntent().getStringExtra("teamNo");
//        if (isUserCenter) {
//            binding.include.liuhaiStatusView.setBackgroundResource(R.color.white);
//            binding.include.rlTitle.setBackgroundResource(R.color.white);
//            binding.include.ivBack.setImageResource(R.mipmap.btn_back3);
//            binding.include.titleView.setTextColor(Color.BLACK);
//        } else {
//            binding.include.liuhaiStatusView.setBackgroundResource(R.mipmap.navigation_bar);
//            binding.include.rlTitle.setBackgroundResource(R.mipmap.navigation_bar);
//            binding.include.ivBack.setImageResource(R.mipmap.back);
//            binding.include.titleView.setTextColor(Color.WHITE);
//        }


        if (serviceQuoteAdapter == null)
            serviceQuoteAdapter = new ServiceQuoteAdapter(this, null);

        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        binding.displayView.setLayoutManager(layoutManager);
        binding.displayView.setAdapter(serviceQuoteAdapter);
        binding.displayView.setLoadingMoreEnabled(true);
        binding.displayView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                if (isUserCenter) {
                    model.getServiceQuoteQueryListUserCenter(false);
                } else {
                    model.getServiceQuoteQueryList(false, teamNo);
                }
            }

            @Override
            public void onLoadMore() {
                if (isUserCenter) {
                    model.getServiceQuoteQueryListUserCenter(true);
                } else {
                    model.getServiceQuoteQueryList(true, teamNo);
                }
            }
        });

        if (isUserCenter) {
            model.getServiceQuoteQueryListUserCenter(false);
        } else {
            model.getServiceQuoteQueryList(false, teamNo);
        }

    }


    /**
     * 杰出人才数据
     *
     * @param list
     * @param isLoadMore
     */
    public void showList(List<ServiceQuoteEntity> list, boolean isLoadMore) {
        binding.displayView.refreshComplete();
        if (isLoadMore) {
            if (null != list && list.size() > 0) {
                binding.displayView.loadMoreComplete();
                serviceQuoteAdapter.addDatas(list);
            } else {
                binding.displayView.setNoMore(true);
            }
            binding.displayView.setVisibility(View.VISIBLE);
        } else {
            if (list.size() == 0) {
                binding.emptyView.setVisibility(View.VISIBLE);
            } else {
                binding.emptyView.setVisibility(View.GONE);
            }
            binding.displayView.refreshComplete();
            binding.displayView.setLoadingMoreEnabled(true);
            serviceQuoteAdapter.setDatas(list);
        }
    }
}
